﻿/*  CamHelper (See http://camhelper.codeplex.com/ or https://bitbucket.org/AndiKS/camhelper for more Info)
    Copyright (C) 2011 Andreas Wimmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using CamHelper.Interpreter;
using NUnit.Framework;

namespace CamHelper.Tests.Interpreter
{
    [TestFixture]
    public class ParameterTest
    {
        [Test]
        public void Simple()
        {
            var p = new Parameter(new ParameterFileLine(null, 4, "# optimization_path		 = 0"));
            Assert.AreEqual(p.BaseEntry, null);
            Assert.AreEqual(p.Category, String.Empty);
            Assert.AreEqual(p.UniqueKey, "optimization_path");
            Assert.AreEqual(p.Key, "Optimization_Path");
            Assert.AreEqual(p.Value, "0");
        }

        [Test]
        public void WithCategory()
        {
            var content =
@"[Par]		// Parameters

# app_ret_ang = 20";

            var file = new ParameterFile(@"C:\Temp\test.par", content);

            var p = file.Parameters[".par.app_ret_ang"];
            Assert.AreEqual(p.Value, "20");
            Assert.AreEqual(p.Category, "Par");
        }

        [Test]
        public void DirectWithCategory()
        {
            var category = "Category";
            var key = "Key";
            var value = "Value";
            var uniqueKey = "category.key";

            var p = new Parameter(category, key, value);
            Assert.That(p.Category, Is.EqualTo(category));
            Assert.That(p.Key, Is.EqualTo(key));
            Assert.That(p.Value, Is.EqualTo(value));
            Assert.That(p.UniqueKey, Is.EqualTo(uniqueKey));
        }

        [Test]
        public void DirectWithCategoryGlobal()
        {
            var category = "Global";
            var key = "Key";
            var value = "Value";
            var uniqueKey = ".global.key";

            var p = new Parameter(category, key, value);
            Assert.That(p.Category, Is.EqualTo(category));
            Assert.That(p.Key, Is.EqualTo(key));
            Assert.That(p.Value, Is.EqualTo(value));
            Assert.That(p.UniqueKey, Is.EqualTo(uniqueKey));
        }

        [Test]
        public void DirectWithCategoryPar()
        {
            var category = "Par";
            var key = "Key";
            var value = "Value";
            var uniqueKey = ".par.key";

            var p = new Parameter(category, key, value);
            Assert.That(p.Category, Is.EqualTo(category));
            Assert.That(p.Key, Is.EqualTo(key));
            Assert.That(p.Value, Is.EqualTo(value));
            Assert.That(p.UniqueKey, Is.EqualTo(uniqueKey));
        }

        [Test]
        public void DirectWithCategoryTool()
        {
            var category = "Tool";
            var key = "Key";
            var value = "Value";
            var uniqueKey = "tool.key";

            var p = new Parameter(category, key, value);
            Assert.That(p.Category, Is.EqualTo(category));
            Assert.That(p.Key, Is.EqualTo(key));
            Assert.That(p.Value, Is.EqualTo(value));
            Assert.That(p.UniqueKey, Is.EqualTo(uniqueKey));
        }

        [Test]
        public void DirectWithOutCategory()
        {
            var category = "";
            var key = "Key";
            var value = "Value";
            var uniqueKey = "key";

            var p = new Parameter(category, key, value);
            Assert.That(p.Category, Is.EqualTo(category));
            Assert.That(p.Key, Is.EqualTo(key));
            Assert.That(p.Value, Is.EqualTo(value));
            Assert.That(p.UniqueKey, Is.EqualTo(uniqueKey));
        }

        [Test]
        public void UniqueKeyTool()
        {
            var category = "Tool";
            var key = "Key";
            var uniqueKey = "tool.key";

            var p = new Parameter(uniqueKey);
            Assert.That(p.Category, Is.EqualTo(category));
            Assert.That(p.Key, Is.EqualTo(key));
            Assert.That(p.UniqueKey, Is.EqualTo(uniqueKey));
        }

        [Test]
        public void UniqueKeyGlobal()
        {
            var category = "Global";
            var key = "Key";
            var uniqueKey = ".global.key";

            var p = new Parameter(uniqueKey);
            Assert.That(p.Category, Is.EqualTo(category));
            Assert.That(p.Key, Is.EqualTo(key));
            Assert.That(p.UniqueKey, Is.EqualTo(uniqueKey));
        }
    }
}
